package com.anxin.registerManagement.service;

import cn.hutool.core.util.ObjectUtil;
import com.anxin.registerManagement.bean.jo.AcademySearchJo;
import com.anxin.registerManagement.bean.persist.Academy;
import com.anxin.registerManagement.mapper.AcademyMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author 叶前呈
 * @date 2022/1/29 12:19
 */
@Service
public class AcademyService {

    private static Logger logger = LoggerFactory.getLogger(AcademyService.class);

    @Autowired
    AcademyMapper academyMapper;

    /**
     * 查询学院
     */
    public PageInfo<Academy> getAcademyList(AcademySearchJo academySearchJo) {
        if (!ObjectUtil.isEmpty(academySearchJo.getPageNum()) && !ObjectUtil.isEmpty(academySearchJo.getPageSize())) {
            PageHelper.startPage(academySearchJo.getPageNum(), academySearchJo.getPageSize());
        }
        // FIXME:学院这里不太一样，因为学院只是单表查询，因此不需要dto输入输出，前端直接请求用户列表，设置各个负责人名称
        List<Academy> academyList = academyMapper.getAcademyList(academySearchJo);
        return new PageInfo<>(academyList);
    }

    /**
     * 添加学院
     */
    public void addAcademy(Academy academy) {
        // TODO：这里需要去判断辅导员、院长、副院长是否存在，以及辅导员、院长、副院长唯一
        academyMapper.insert(academy);
        logger.info("添加学院：{}，成功", academy);

    }

    /**
     * 修改学院
     */
    public void updateAcademy(Academy academy) {
        // TODO:同理与添加学院一样校验，同时需要判断学院名称是否存在
        academyMapper.updateById(academy);
        logger.info("修改学院：{}，成功", academy);
    }

    /**
     * 删除学院
     */
    public void deleteAcademy(int id) {
        // TODO:这里删除的是否需要判断是否有班级、简单处理即有班级则不允许删除
        academyMapper.deleteById(id);
        logger.info("删除学院id：{}，成功", id);
    }

    /**
     * 获取所有学院
     */
    public List<Academy> getAllAcademy() {
        return academyMapper.selectList(null);
    }
}
